#include "count.h"

/*
void count(){
  char c[5];
  do{
    lire(c,5);
    ecrire("\n");
  }while(strcmp(c,"exit"));
  tuer(1,8);
  }*/

/*
void count(){
  char buf[3];
  int child[2];
  child[0] = fourchette(12,"uart_test",NULL);
  superviser(child[0]);
  child[1] = fourchette(32,"uart_test",NULL);
  superviser(child[1]);
  ecrire("Now, the supervisor waits \n");
  message m;
  while(1){
    recevoir_priorite(SUPERVISION_MESSAGE, &m);
    kprint_string("\nProcess ");
    int crashed = message_get_from(&m);
    int code = message_get_int_value(&m);
    kprint_string(itoa(crashed,buf,3));
    kprint_string(" terminated with code ");
    kprint_string(itoa(code,buf,3));
    kprint_string("\n");
    int r;
    attendre(crashed,&r);
    ecrire_lcd(itoa(r,buf,3));
    if(code != 0){
      if(crashed == child[0]){
	child[0] = fourchette(12,"uart_test",NULL);
	superviser(child[0]);
      }
      else{
	child[1] = fourchette(32,"uart_test",NULL);
	superviser(child[1]);
      }
    }
     kprint_string("Process restarted\n");
  }
  quitter(0);
  }*/

void count(){
  char buf[15];
  char* b = allouer(4*sizeof(char));
  ecrire(itoa((int)b, buf, 15));
  char *b1 = allouer(4*sizeof(char));
  ecrire(itoa((int)b1, buf, 15));
  strncpy(b1,"b1",4);
  if(b != NULL){
    strncpy(b,"bob",4);
    ecrire(b);
  }else
    ecrire("Allocation failed\n");
  ecrire("\nb1: ");
  ecrire(b1);
  char* b2 = allouer(4*sizeof(char));
  ecrire(itoa((int)b2, buf, 15));
  ecrire("\nb2: ");
  strncpy(b2,"b2",4);
  ecrire(b2);
  char* b3 = allouer(5*sizeof(char));
  ecrire(itoa((int)b3,buf,15));
  ecrire("\nb3: ");
  ecrire(b3);
  char* b4 = allouer(6*sizeof(char));
  ecrire(itoa((int)b4,buf,15));
  ecrire("\nb4: ");
  strncpy(b4,"b4",6);
  ecrire(b4);
  char* b6 = allouer(6*sizeof(char));
  ecrire(itoa((int)b6,buf,15));
  ecrire("\nb6: ");
  strncpy(b6,"b6",6);
  ecrire(b6);
  liberer(b1);
  liberer(b3);
  liberer(b2);
  char* b5 = allouer(48*sizeof(char));
  ecrire(itoa((int)b5,buf,15));
  ecrire("\nb5: ");
  ecrire(b5);
  if(obtenir_priorite(obtenir_pid()) != 41)
    fourchette(41, "count",NULL);
  quitter(0);
}
